#region Summary

// 
// Owner : JackieHan 
// 
// Solution : LearnSolution 
// 
// Project : JackieHan.NHibernate3.Configuration
// 
// File : LambdaConfiguration.cs
// 
// CopyRight : Copyright © 2010-2011 Skomart Corporation, All Rights Reserved 
// 
// Summary : Lambda表达式配置
// 
// History : 
//			2010-09-13 13:06:25	    Create 
// 

#endregion

#region Using

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using NHibernate;
using NHibernate.AdoNet;
using NHibernate.ByteCode.Castle;
using NHibernate.Cache;
using NHibernate.Cfg;
using NHibernate.Cfg.Loquacious;
using NHibernate.Dialect;
using NHibernate.Driver;
using NHibernate.Exceptions;
using NHibernate.Hql.Ast.ANTLR;
using NHibernate.Linq.Functions;
using NHibernate.Transaction;
using NHibernate.Type;
using NHibernate.Connection;
using NHConfiguration=NHibernate.Cfg.Configuration;
#endregion

namespace JackieHan.NHibernate3.Configuration
{
    /// <summary> 
    /// Lambda表达式配置
    /// </summary>
    public class LambdaConfiguration
    {
        public static NHConfiguration CompletedConfig()
        {
            NHConfiguration cfg = new NHConfiguration();
            cfg = new NHibernate.Cfg.Configuration();
            cfg.SessionFactoryName("lambda");   //配置助记名
            cfg.Cache(c =>//缓存配置
                          {
                              c.DefaultExpiration = 15; //超时时间
                              c.Provider<HashtableCacheProvider>(); //缓存提供程序
                              c.QueryCache<StandardQueryCache>();//缓存查询提供程序
                              c.RegionsPrefix = "learn";//缓存前缀
                              c.UseMinimalPuts = true;//设置缓存性能
                          });
            cfg.CollectionTypeFactory<DefaultCollectionTypeFactory>();//设置连接类型工厂
            cfg.DataBaseIntegration(db =>//数据库基本设置
                                        {
                                            db.AutoCommentSql = true;//自动注释生成的Sql,便于调试
                                            db.Batcher<SqlClientBatchingBatcherFactory>();//批量操作提供程序工厂
                                            db.BatchSize = 15;//批量更新设置
                                            db.ConnectionProvider<DriverConnectionProvider>();//
                                            db.ConnectionReleaseMode = ConnectionReleaseMode.AfterTransaction;
                                            db.ConnectionString =
                                                ConfigurationManager.ConnectionStrings["learn"].ConnectionString;
                                            db.Dialect<MsSql2005Dialect>();
                                            db.Driver<SqlClientDriver>();
                                            db.ExceptionConverter<SQLStateConverter>();
                                            db.HqlToSqlSubstitutions = "true 1,false 0,yes 'Y' no 'N'";
                                            db.IsolationLevel = IsolationLevel.ReadCommitted;
                                            db.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote;
                                            db.LogFormatedSql = true;
                                            db.LogSqlInConsole = true;
                                            db.MaximumDepthOfOuterJoinFetching = 13;
                                            db.PrepareCommands = true;
                                            db.SchemaAction = SchemaAutoAction.Create;
                                            db.Timeout = 30;
                                            db.TransactionFactory<AdoNetTransactionFactory>();
                                        });
            cfg.HqlQueryTranslator<ASTQueryTranslatorFactory>();
            cfg.LinqToHqlGeneratorsRegistry<DefaultLinqToHqlGeneratorsRegistry>();
            cfg.Mappings(map =>
                             {
                                 map.DefaultCatalog = "learnCatalog";
                                 map.DefaultSchema = "learnSchema";
                             });
            cfg.Proxy(proxy =>
                          {
                              proxy.ProxyFactoryFactory<ProxyFactoryFactory>();
                              proxy.Validation = false;
                          });

            return cfg;
        }
    }
}